package com.four.user.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.four.user.service.UserService;
import com.four.user.service.impl.UserServiceImpl;
@WebServlet("/addUser.do")
public class AddUserServlet extends HttpServlet{


	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("UTF-8");
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		String age = req.getParameter("age");
		String gender = req.getParameter("gender");
		String remake = req.getParameter("remake");
		UserService service = new UserServiceImpl();
		boolean result = service.addUser(username, password, age, gender, remake);
		System.out.println("添加结果：" + result);
		req.getRequestDispatcher("view/users.html").forward(req, resp);
	}
	

}